//
//  CategaryVC.m
//  NotepadApp
//
//  Created by yobet on 2018/4/16.
//  Copyright © 2018年 HJ. All rights reserved.
//

#import "CategaryVC.h"

@interface CategaryVC ()
@property(nonatomic,strong) NSMutableArray * dataArray;
@property(nonatomic,assign) BOOL isSegment;
@property(nonatomic,strong) NSMutableArray *rightArray;
@end

@implementation CategaryVC

-(NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = @[@{@"image":@"office",@"title":@"办公"},@{@"image":@"lottery",@"title":@"彩票"},@{@"image":@"catering",@"title":@"餐饮"},@{@"image":@"pet",@"title":@"宠物"},@{@"image":@"communication",@"title":@"沟通"},@{@"image":@"shop",@"title":@"购物"},@{@"image":@"kid",@"title":@"孩子"},@{@"image":@"communication",@"title":@"交通"},@{@"image":@"living",@"title":@"居家"},@{@"image":@"donate",@"title":@"捐赠"},@{@"image":@"cash gift ",@"title":@"礼金"},@{@"image":@"gift",@"title":@"礼物"},@{@"image":@"snacks",@"title":@"零食"},@{@"image":@"travel",@"title":@"旅行"},@{@"image":@"hairdressing",@"title":@"美容"}, @{@"image":@"car",@"title":@"汽车"},@{@"image":@"commodity",@"title":@"商品"},@{@"image":@"set",@"title":@"设置"}, @{@"image":@"social contact",@"title":@"社交"},@{@"image":@"income",@"title":@"收入"},@{@"image":@"book",@"title":@"书籍"}, @{@"image":@"vegetables",@"title":@"蔬菜"},@{@"image":@"numerical code",@"title":@"数码"},@{@"image":@"fruits",@"title":@"水果"}, @{@"image":@"maintain",@"title":@"维修"},@{@"image":@"cigarette",@"title":@"烟酒"},@{@"image":@"clothing ",@"title":@"衣服"},@{@"image":@"medical treatment",@"title":@"医疗"},@{@"image":@"recreation",@"title":@"娱乐"},@{@"image":@"exercise ",@"title":@"运动"},@{@"image":@"elder",@"title":@"长辈"},@{@"image":@"housing",@"title":@"住房"},@{@"image":@"study",@"title":@"学习"}
            ].mutableCopy;
    }
    return _dataArray;
}

-(NSMutableArray *)rightArray {
    if (!_rightArray) {
        _rightArray =@[@{@"image":@"salary",@"title":@"工资"},@{@"image":@"part-time job",@"title":@"兼职"},
                       @{@"image":@"cash gift",@"title":@"礼金"},@{@"image":@"manage money matters",@"title":@"理财"},
                       @{@"image":@"else",@"title":@"其他"},@{@"image":@"setting up",@"title":@"设置"}
                       ].mutableCopy;
    }
    return _rightArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.isSegment = YES;
    [self configSegmentWithleftTitle:@"支出" rightTitle:@"收入"];

}

-(void)segmentCilik:(id)sender {
    switch ([sender selectedSegmentIndex]) {
        case 0:
            self.isSegment = YES;
            break;
        case 1:
            self.isSegment = NO;
            break;
        default:
            break;
    }
    [self.tableView reloadData];

}
-(void)configTableView {
    self.tableViewStyle = UITableViewStylePlain;
    [super configTableView];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.isSegment ? self.dataArray.count : self.rightArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (self.isSegment) {
        cell.imageView.image =[UIImage imageNamed:self.dataArray[indexPath.row][@"image"]];
        cell.textLabel.text = self.dataArray[indexPath.row][@"title"];
    }else {
        cell.imageView.image =[UIImage imageNamed:self.rightArray[indexPath.row][@"image"]];
        cell.textLabel.text = self.rightArray[indexPath.row][@"title"];
    }
    return cell;
}
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        if (self.isSegment) {
            [self.dataArray removeObjectAtIndex:indexPath.row];
        }else {
            [self.rightArray removeObjectAtIndex:indexPath.row];
        }
        [tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    }
}
@end
